<?php

/**
 * EditUserName form.
 *
 * @package    cpfaizenay
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: EditUserNameForm.class.php 20147 2009-07-13 11:46:57Z FabianLange $
 */
class EditUserNameForm extends BaseForm {

    public function configure() {

        $user = sfContext::getInstance()->getUser()->getGuardUser();

        $this->setWidgets(array(
            'username'         => new sfWidgetFormInputText()
        ));

        $this->setValidator( 'username', new sfValidatorApplyUsername() );

        $this->widgetSchema->setFormFormatterName('list');
        $this->widgetSchema->setNameFormat('edit_username[%s]');
   }

   public function save($con = null) {
       $user = sfContext::getInstance()->getUser()->getGuardUser();
       $user->setUserName( $this->getValue('username') );
       $user->save();
   }
}
